package com.threadmethod.AtomicLong;

import java.util.Random;

/**
 * @PackageName:com.threadmethod.AtomicLong
 * @ClassName:Test01
 * @Description: 模拟服务器的请求总数，处理成功数，处理失败数
 * @Author: zhangxiaoyu
 * @date 2020/12/10 17:40
 */
public class Test01 {

    public static void main(String[] args) {
         //通过线程模拟请求 在实际应用中可以通过ServletFilter调用Indicator计数器的相关方法
        for (int i=0;i<10000;i++){
            new Thread(new Runnable() {
                @Override
                public void run() {
                    //每个线程就是一个请求请求总数要加一
                    Indicator.getInstance().newRequestReceive();
                    int num = new Random().nextInt();
                    if(num%2==0){  //偶数模拟成功
                        Indicator.getInstance().requestProcessSuccess();
                    }else {
                        Indicator.getInstance().requestProcessFailure();
                    }

                }
            }).start();
        }

        try {
            Thread.sleep(1000);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }

        System.out.println(Indicator.getInstance().getRequestCount());
        System.out.println(Indicator.getInstance().getSuccessRequestCount());
        System.out.println(Indicator.getInstance().getFailRequestCount());

    }


}
